/**
 * ReportGear(2011)
 */
package com.reportgear.designer.gui.config;

import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JToolBar;

/**
 * 工具栏定义
 * 
 * @version 1.0 2011-4-26
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class ToolBarDef implements Cloneable {
	private List<ShortCut> shortcutList = new ArrayList<ShortCut>();

	public static JToolBar createJToolBar() {
		return createJToolBar(FlowLayout.LEFT);
	}

	public static JToolBar createJToolBar(int align) {
		JToolBar toolbar = new JToolBar();
		toolbar.setFloatable(false);
		toolbar.setRollover(true);
		toolbar.setLayout(new FlowLayout(align, 2, 1));
		return toolbar;
	}

	public int getShortCutCount() {
		return this.shortcutList.size();
	}

	public ShortCut getShortCut(int index) {
		return this.shortcutList.get(index);
	}

	public void addShortCut(ShortCut shortCut) {
		this.shortcutList.add(shortCut);
	}

	public void clearShortCuts() {
		this.shortcutList.clear();
	}

	public void updateToolBar(JToolBar toolbar) {
		toolbar.removeAll();

		for (ShortCut sc : this.shortcutList) {
			sc.intoJToolBar(toolbar, null);
		}
	}

	public ToolBarDef clone() {
		try {
			return (ToolBarDef) super.clone();
		} catch (CloneNotSupportedException e) {
			throw new InternalError();
		}
	}
}